class Product
  include Mongoid::Document
  include Mongoid::Timestamps

  field :name, type: String
  field :price, type: Float
  field :avatar_q_key, type: String
  field :avatar_q_bucket, type: String
  field :memo, type: String

  has_many :machine_grids

  validates :name, :price, :avatar_q_key, :avatar_q_bucket, :memo, presence: true

  def image_url(version = nil)
    ::AnAnCommon::Qiniu.url(avatar_q_key, version)
  end
end
